<template>
  <div class="home">
    <myheader :title="title"></myheader>
    <myinput @send:value="getval"></myinput>
    <div class="topnav">
      <div class="t-left">
        <p @click="showtab">{{ text }}</p>
        <span v-show="showarrow">&or;</span>
        <span v-show="!showarrow">&and;</span>
      </div>
      <div class="t-right">
        <span>最新贴</span>
        <span>精华帖</span>
        <span>高收藏</span>
      </div>
    </div>
    <!-- 下拉列表 -->
    <transition name="slide">
      <div class="mask" v-show="showarrow">
        <ul>
          <li v-for="(item, i) in lnav" :key="i" @click="filte(item, i)">
            {{ item }}
          </li>
        </ul>
      </div>
    </transition>

    <!-- 主页内容 -->
    <div class="main">
      <ul>
        <li v-for="item in list" :key="item.id" @click="jump(item)">
          <div class="m-top">
            <div class="m-top-left">
              <img src="" alt="" />
            </div>
            <div class="m-top-cen">
              <p>{{ item.nickname }}</p>
              <span>0</span>
              <span>{{ item.address }}</span>
            </div>
            <div class="m-top-right">
              <span style="color: rgb(97, 248, 178)">New</span>
              <p>{{ item.bankuai }}</p>
            </div>
          </div>
          <div class="m-bot">
            <div class="m-bot-top">
              <h4>{{ item.question }}</h4>
            </div>
            <div class="m-bot-bot">
              <span>{{ item.ctime }}</span>
              <span>{{ item.look }}</span>
              <span>{{ item.message }}</span>
            </div>
          </div>
        </li>
      </ul>
    </div>
    <myfooter></myfooter>
  </div>
</template>

<script>
import myheader from "@/components/myheader";
import myfooter from "@/components/myfooter";
import myinput from "@/components/myinput";
export default {
  name: "Home",
  components: { myheader, myfooter, myinput },
  data() {
    return {
      title: "牛刀问答",
      text: "全部版块",
      showarrow: false,
      keyword: "",
      list: [],
      copylist: [],
      lnav: [
        "全部版块",
        "APP开发",
        "平台问题",
        "经验分享",
        "开发交流",
        "官方公告",
        "组件使用",
        "小程序开发",
      ],
    };
  },
  created() {
    this.$axios({
      url: "/test.json",
      method: "get",
    }).then((res) => {
      console.log(res.data);
      this.list = res.data;
      this.copylist = this.list;
      
    });
  },
  methods: {
    showtab() {
      this.showarrow = !this.showarrow;
    },
    filte(item, i) {
      this.text = item;
      this.showarrow = false;
      if (item == "全部版块") {
        this.list = this.copylist;
      } else {
        this.list = this.copylist;
        this.list = this.list.filter((child) => {
          return child.bankuai == item;
        });
      }
    },
    getval(data) {
      this.keyword = data;
      this.list = this.copylist;
      this.list = this.list.filter((child) => {
        return child.question.includes(data);
      });
    },
    jump(obj){
      this.$router.push({path:'/detail',query:{obj}})
    }
  },
};
</script>

<style lang="scss" scoped>
.home {
  width: 100%;
  height: 100%;
  padding-bottom: 50px;
  .myinput {
    width: 90%;
    margin: 10px auto;
  }
  .topnav {
    width: 100%;
    height: 40px;
    display: flex;
    color: rgb(54, 158, 243);
    .t-left {
      flex: 1.4;
      display: flex;
      justify-content: center;
      align-items: center;
      position: relative;
      span {
        position: absolute;
        right: 15px;
        background-color: rgb(238, 236, 236);
      }
    }
    .t-right {
      flex: 3;
      display: flex;
      justify-content: flex-start;
      align-items: center;
      span {
        display: inline-block;
        border: 1px solid rgb(54, 158, 243);
        padding: 3px 6px;
        border-radius: 4px;
        margin-left: 12px;
      }
    }
  }
  .mask {
    width: 30%;
    height: calc(100% - 200px);
    background-color: rgba(0, 0, 0, 0.3);
    position: absolute;
    top: 150px;
    left: 0;
    ul {
      width: 100%;
      height: 100%;
      padding: 5px;
      display: flex;
      flex-direction: column;
      justify-content: space-around;
      align-items: center;
      li {
        width: 100%;
        padding: 10px 0;
        list-style: none;
        border-bottom: 2px solid #fff;
        color: #fff;
      }
    }
  }
  .slide-enter,
  .slide-leave-to {
    height: 0;
    z-index: -10;
  }
  .slide-enter-to,
  .slide-leave {
    height: calc(100% - 200px);
    z-index: 1;
  }
  .slide-enter-active,
  .slide-leave-active {
    transition: all 0.5s linear;
  }
  .main {
    width: 100%;
    height: calc(100% - 150px);
    overflow-y: scroll;

    ul {
      width: 100%;
      height: 100%;
      li {
        width: 100%;
        padding: 5px 10px;
        background-color: #fff;
        margin-bottom: 5px;
        .m-top {
          display: flex;
          .m-top-left {
            width: 50px;
            height: 50px;
            border-radius: 50%;
            background-color: rgb(212, 208, 208);
          }
          .m-top-cen {
            width: 60%;
            text-align: left;
            padding: 0 10px;
            color: rgb(221, 219, 219);
          }
          .m-top-right {
            width: 26%;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            p {
              color: #fff;
              padding: 5px;
              background-color: rgb(66, 187, 243);
              border-radius: 15px;
            }
          }
        }
        .m-bot {
          width: 100%;
          .m-bot-top {
            text-align: left;
            margin: 10px 0;
          }
          .m-bot-bot {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding-right: 40px;
            color: rgb(221, 219, 219);
          }
        }
      }
    }
  }
}
</style>
